home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
BUS
/
TMCM Software and Labs.sit
/
Software for TMCM 7_95
/
Files for Lab 5
/
ListSum
< prev
next >
Wrap
Text File
|
1994-04-16
|
2KB
|
62 lines
; Complete this program so that it will add up the list
; of numbers starting at the location with label "List".
; The list of numbers ends with a 0. Your program should
; have a loop that gets the next number, checks if it
; is zero and jumps to a halt instruction if it is. If
; the number is not zero, the loop should procede to add
; it to the "Sum" and then jump to the start of the loop
; for the next number. (READ ALL COMMENTS BELOW BEFORE
; WORKING ON THIS.)
lod-c 0 ; Store the number 0 in location "Sum"
sto Sum ; to get ready to start adding.
lod-c List ; Get the number "List" in memory location
sto NextNum ; and store it in memory location NextNum.
; (Remember that a label is really just a
; number!)
Loop: lod-i NextNum ; Get the next number in the list.
; (Note the use of indirect addressing!)
??? ; DO YOUR STUFF HERE:
; Test if the number is zero; if
; it is, then end the program.
; Otherwise, add the number to Sum,
; then add 1 to NextNum, then
; return to the start of the loop
Done: hlt ; program ends if you jump to this location
NextNum: data ; This location will hold the ADDRESS
; of the next number that needs to be
; added to the Sum. At the beginning
; of the program, it is loaded with the
; number, List, which is the address of
; the first number to be added. After
; each number is added, 1 should be
; added to NextNum to make it point to
; the next number in the list.
Sum: data ; At the end of the program, this
; location should hold the sum of the
; numbers in the list. It is set to
; 0 at the start of the program, and
; then the numbers are added to it one
; by one.
List: 123 ; This is the list of numbers to be added
37
103
12
93
88
207
2
124
198
73
0 ; This 0 marks the end of the list